package cn.mall.poster.service.impl;

import cn.mall.base.utils.PageList;
import cn.mall.goods.domain.Goods;
import cn.mall.order.domain.Order;
import cn.mall.poster.domain.Poster;
import cn.mall.poster.mapper.PosterMapper;
import cn.mall.poster.service.IPosterService;
import cn.mall.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xizhou
 * @since 2024-04-30
 */
@Service
public class PosterServiceImpl extends BaseServiceImpl<Poster> implements IPosterService {

    @Autowired
    private PosterMapper posterMapper;

    @Override
    public void update(Poster poster) {
         if(poster.getType()!=3){
             String result = processString(poster.getImgurl());
             poster.setImgurl("http://webshoppingfour.com/pic/"+result);
             posterMapper.update(poster);
         }else{
             posterMapper.update(poster);
         }

    }


    @Override
    public void insert(Poster poster) {
        if(poster.getType()!=3){
            String result = processString(poster.getImgurl());
            poster.setImgurl("http://webshoppingfour.com/pic/"+result);
            posterMapper.insert(poster);
        }else {
            posterMapper.insert(poster);
        }
    }

    @Override
    public List<Poster> loadBylunbopic() {
        return posterMapper.loadlunbopic();
    }

    @Override
    public List<Poster> getboard() {
        return posterMapper.loadByboard();
    }


    private String processString(String original) {
        int lastIndexOfSlash = original.lastIndexOf("/");
        if (lastIndexOfSlash != -1) {
            return original.substring(lastIndexOfSlash + 1);
        } else {
            // 如果原始字符串中没有斜杠，则返回原始字符串或根据需要处理
            return original;
        }
    }
}
